<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$basic=$this->plugin_setting('basic');
$return['banner']=$basic['image'];
$return['basic']=$basic;
set_html('title','创建活动');
if($_RQ['op']=='main'){
	//查询在进行的项目
	$rid = intval($_RQ['rid']);
	$post=array();
	if($_RQ['postdata']){
		$postdata=get_postdata();
		if(empty($postdata['title'])){
			exi('活动标题不能为空！','error');
		}
		if(empty($postdata['address'])){
			exi('活动地址不能为空！','error');
		}
		if(empty($postdata['start'])){
			exi('活动开始时间不能为空！','error');
		}
		if(empty($postdata['end'])){
			exi('活动截止时间不能为空！','error');
		}
		if($postdata['money']<0){
			exi('报名费用不得低于0！','error');
		}
		if(!$postdata['mannum']){
			exi('允许最大报名人数不能为空！','error');
		}
		if($postdata['mannum']<0){
			exi('允许最大报名人数不得低于0！','error');
		}
		
		if(empty($postdata['image'])){
			exi('活动封面图不能为空！','error');
		}
		if(empty($postdata['images'])){
			exi('活动幻灯片不能为空！','error');
		}
		$start=strtotime($postdata['start']);
		$start=date('Y-m-d H:i',$start);
		$end=strtotime($postdata['end']);
		$end=date('Y-m-d H:i',$end);
		//print_r($postdata['images']);exit;
		$hdp=array();
		foreach($postdata['images'] as $img){
			$hdp[]['image']=$img;
		}
		//判断字段必填
		if(!empty($postdata['fileds'])){
			foreach($postdata['fileds'] as $item){
				if($item['is_must'] && empty($item['data'])){
					exi('请填写:'.$item['title'],'error');
				}
			}
		}
		if($basic['shenhe']){
			$status=0;
		}else{
			$status=1;
		}
		if($postdata['money']>0){
			$ispay=1;
		}else{
			$ispay=0;
		}
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'title'=>$postdata['title'],
			'status'=>$status,
			'ispay'=>$ispay,
			'time'=>$start,
			'end'=>$end,
			'mannum'=>$postdata['mannum'],
			'money'=>$postdata['money'],
			'address'=>$postdata['address'],
			'image'=>$postdata['image'],
			'remark'=>$postdata['description'],
			'hdp'=>ijson_encode($hdp),
		//	'fileddata'=>ijson_encode($postdata['fileds']),
			'createtime'=>TIMESTAMP
		);
		pdo_insert('jy_zhongyi_baoming_list',$insert);
		$id=pdo_insertid();
		if($basic['shenhe']){
			exi('上传活动成功,等待管理员审核','success','jy_zhongyi/index/list');
		}else{
			exi('上传活动成功','success','jy_zhongyi/index/list');
		}
	}
	$post['images']=array();
	$return['post']=$post;
	$return['list']=$list;
	$return['province']=cfc('tools')->pcd();
	exi($return);

}
